CentOS 6
Sponsored Link

OpenStack Havana - Swift - How to Use
2013/10/28
 
This example configures with the environment below.
This example shows to use Swift Storage from a Client Machine. (it's the one 10.0.0.20 below)
                               |
     +------------+            |            +-----------+
     |  Auth Node |10.0.0.30   |   10.0.0.50|   Proxy   |
     | (Keystone) |------------+------------|    Node   |
     +------------+            |            +-----------+             +----------+
                               |                             10.0.0.20|  Client  |
      +------------------------+-----------------------+--------------|  Machine |
      |                        |                       |              +----------+
      |10.0.0.51               |10.0.0.52              |10.0.0.53
+-----------+            +-----------+           +-----------+
|  Storage  |            |  Storage  |           |  Storage  |
|   Node1   |------------|   Node2   |-----------|   Node3   |
+-----------+            +-----------+           +-----------+

[1] Add a user for using Swift in Keystone Authentication Node.
By the way, if you'd like to use Swift Quickly, it's unnecessarry to add a new user, it's posibble to use with a admin or swift user in Keystone.
# add swiftservice tenant

[root@dlp ~(keystone)]#
keystone tenant-create --name swiftservice --description "Swift Users Tenant" --enabled true

+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |        Swift Users Tenant        |
|   enabled   |               True               |
|      id     | 8737642a92884936bef791f5aef7fffe |
|     name    |           swiftservice           |
+-------------+----------------------------------+

# add swiftoperator role

[root@dlp ~(keystone)]#
keystone role-create --name swiftoperator

+----------+----------------------------------+
| Property |              Value               |
+----------+----------------------------------+
|    id    | a0706b7be76c47b99b54b110028fe084 |
|   name   |          swiftoperator           |
+----------+----------------------------------+

# add a user

[root@dlp ~(keystone)]#
keystone user-create --tenant swiftservice --name user01 --pass userpassword --enabled true

+----------+----------------------------------+
| Property |              Value               |
+----------+----------------------------------+
|  email   |                                  |
| enabled  |               True               |
|    id    | 1baf427662bc4c4cb03c896233646c71 |
|   name   |              user01              |
| tenantId | 8737642a92884936bef791f5aef7fffe |
+----------+----------------------------------+

# add the user in swiftoperator role

[root@dlp ~(keystone)]#
keystone user-role-add --user user01 --tenant swiftservice --role swiftoperator

[2] This is Client's settings.
Install Keystoneclient, Swiftclient first.
# install from EPEL OpenStack, EPEL

[root@client ~]#
yum --enablerepo=openstack-havana,epel -y install python-keystoneclient python-swiftclient
[3] Load environment variables first. ( it's just the value for a user added in [1] )
[root@client ~]#
vi ~/keystonerc_swift
export OS_USERNAME=user01
export OS_PASSWORD=userpassword
export OS_TENANT_NAME=swiftservice
export OS_AUTH_URL=http://10.0.0.30:35357/v2.0/
export PS1='[\u@\h \W(swift)]\$ '
[root@client ~]#
chmod 600 ~/keystonerc_swift

[root@client ~]#
source ~/keystonerc_swift

[root@client ~(swift)]#
echo "source ~/keystonerc_swift " >> ~/.bash_profile
# show status

[root@client ~(swift)]#
swift stat

   Account: AUTH_8737642a92884936bef791f5aef7fffe
Containers: 0
   Objects: 0
     Bytes: 0
Content-Type: text/plain; charset=utf-8
X-Timestamp: 1382968354.62547
X-Put-Timestamp: 1382968354.62547
[4] Create a Container for files.
[root@client ~(swift)]#
swift post test_container

[root@client ~(swift)]#
swift list

test_container
# just created

[5] Upload a file in local to a Container.
# upload test.txt

[root@client ~(swift)]#
swift upload test_container test.txt

test.txt
[root@client ~(swift)]#
swift list test_container

test.txt
# just uploaded

[6] Download a file from Swift Storage to local.
# remove a file

[root@client ~(swift)]#
rm test.txt
[root@client ~(swift)]#
swift download test_container test.txt

test.txt [headers 0.621s, total 0.621s, 0.000 MB/s]
[root@client ~(swift)]#
total 44
-rw-------. 1 root root  1242 Apr 11  2012 anaconda-ks.cfg
-rw-r--r--. 1 root root  9017 Apr 11  2012 install.log
-rw-r--r--. 1 root root  3091 Apr 11  2012 install.log.syslog
-rw-------  1 root root   175 Oct 28 13:52 keystonerc_swift
-rw-r--r--  1 root root     9 Oct 28 22:53 test.txt
[7] Delere a file on Storage.
[root@client ~(swift)]#
swift delete test_container test.txt

test.txt
[root@client ~(swift)]#
swift list test_container

test2.txt
# deleted (test.txt)

[8] Delete a Container on Storage.
[root@client ~(swift)]#
swift delete test_container

[root@client ~(swift)]#
swift list

 
# just deleted

 
Tweet